package day11.byteStream;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * @author Xiao
 * @date 2021/8/1
 */
public class OutputDemo03 {
    /**
     * 如何写换行
     * 调用write()方法，写出”\r\n”.getBytes()即可
     * 如何文件续写
     * 使用FileOutputStream(String name,boolean append)构造方法
     * 构造方法中第二个参数传递true，则在文件末尾继续写数据
     */
    public static void main(String[] args) throws IOException {
        FileOutputStream fos = new FileOutputStream("videoPractice\\src\\day11\\" +
                "byteStream\\demo03.txt",true);
//        printNewLine(fos, "HelloWorld");
        printNewLine(fos, "我爱Java");
    }
    private static void printNewLine(FileOutputStream fos, String s) throws IOException {
        fos.write(s.getBytes());
        fos.write("\r\n".getBytes());
        fos.write(s.getBytes());
        fos.write("\r\n".getBytes());
        fos.write(s.getBytes());
        fos.write("\r\n".getBytes());
        fos.write(s.getBytes());
        fos.write("\r\n".getBytes());
    }
}
